﻿using FriendStar.Code;
using FriendStar.Domain.Entity.VBaseData;
using FriendStar.Domain.IRepository.VBaseData;
using FriendStar.Repository.VBaseData;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;

namespace FriendStar.Application.VBaseData
{
    public class V_CPK_22_CK_StoStorageCard_MidApp
    {
        private IV_CPK_22_CK_StoStorageCard_MidRepository service = new V_CPK_22_CK_StoStorageCard_MidRepository();

        public List<V_CPK_22_CK_StoStorageCard_MidEntity> GetList(Pagination pagination, string FSupplierNO, string FProductionNO, string FCurDate, string FAccountDate, string FStoreSetNO, string FVoucherNo, string type)
        {
            var expression = ExtLinq.True<V_CPK_22_CK_StoStorageCard_MidEntity>();
            string extWhere = "";
            Dictionary<string, string> whereobj = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(FSupplierNO))
            {
                expression = expression.And(t => t.FSupplierNO == FSupplierNO);
            }
            if (!string.IsNullOrEmpty(FProductionNO))
            {
                expression = expression.And(t => t.FProductionNO.Contains(FProductionNO));
            }
            if (!string.IsNullOrEmpty(FStoreSetNO))
            {
                expression = expression.And(t => t.FStoreSetNO.Contains(FStoreSetNO));
            }
            if (!string.IsNullOrEmpty(FVoucherNo))
            {
                expression = expression.And(t => t.FVoucherNo.Contains(FVoucherNo));
            }
            if (!string.IsNullOrEmpty(FCurDate))
            {
                extWhere = " FCurDate=@FCurDate ";
                whereobj.Add("FCurDate", FCurDate);
            }
            if (!string.IsNullOrEmpty(FAccountDate))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and FAccountDate=@FAccountDate ";
                }
                else
                {
                    extWhere = " FAccountDate=@FAccountDate ";
                }
                whereobj.Add("FAccountDate", FAccountDate);
            }
            return service.FindList(expression, pagination, extWhere, whereobj).ToList();
        }

        public List<V_CPK_22_CK_StoStorageCard_MidEntity> GetPrintStorgeCardMidData(string regids)
        {
            var list = regids.Split(',');
            return service.IQueryable().In(p => p.FRegisterID, list).ToList();
        }
    }
}
